//(function (doc, win) {
//var docEl = doc.documentElement,
//resizeEvt = 'orientationchange' in window ? 'orientationchange' : 'resize',
//recalc = function () {
//var clientWidth = docEl.clientWidth;
//if (!clientWidth) return;
//docEl.style.fontSize = 20 * (clientWidth / 320) + 'px';
//};

//if (!doc.addEventListener) return;
//win.addEventListener(resizeEvt, recalc, false);
//doc.addEventListener('DOMContentLoaded', recalc, false);
//})(document, window);

/*
	options:{
		url : post请求地址
		data:请求json数据
		success_msg:成功提示信息
		fail_msg:失败提示信息
		action:成功执行动作，【refresh,tips,callback,redirect,none】分别为刷新页面，提示，回调
		redirect:跳转地址
		callback:function(){}回调函数
	}
*/
var cityDatas = {};
function ajax(options){
	if(options.open_load == undefined) options.open_load=true;
	if(options.open_load) layer.load(1);
	options.error_msg = options.error_msg || "系统内部异常";
	options.actions = options.actions || "tips";
	$.ajax({
		type:"POST",
		dataType:"json",
		url:options.url,
		data:options.data,
		success:function(result){
			if(options.open_load) layer.closeAll('loading');
			var msg = options.success_msg || result.result_msg;
			if (options.actions != "data" && options.actions != "system")
				layer.msg(msg);
			setTimeout(function(){
				excute(result,options);
			},1000);
		},
		error: function (XMLHttpRequest, textStatus, errorThrown) {
            layer.msg(options.error_msg);
            layer.closeAll('loading');
        }
	});
}

function excute(result,options){
	if(result.result_code == 1000){
		if (options.actions == "refresh")
		    window.location.reload();
		else if (options.actions == "callback")
		    options.callback();
		else if (options.actions == "redirect")
		    window.location.href = options.redirect;
		else if (options.actions == "data")
		    cityDatas = result.data;
		else if (options.actions == "system")
		    window.location.href = result.result_msg;
	}else if(result.result_code == 401){
		window.location.href = "/home/login";
	}else{
		options.fail_msg = options.fail_msg || result.result_msg;
		layer.msg(options.fail_msg);
	}
}